<template>
  <h2>sum：{{ sum }}</h2>
  <button type="" @click="sum++">点击+1</button>
  <hr />
  <h2>msg：{{ msg }}</h2>
  <button type="" @click="msg += '！'">点击+！</button>
  <hr />
  <h2>{{ `姓名：${person.name}  年龄：${person.age}` }}</h2>
  <h2>薪水：{{ person.job.j1.salary }}K</h2>
  <button type="" @click="person.name += '~'">修改姓名</button>
  <button type="" @click="person.age++">增长年龄</button>
  <button type="" @click="person.job.j1.salary++">涨薪</button>
</template>

<script>
import { ref, watch, reactive,watchEffect } from "vue";
export default {
  name: "App",
  setup() {
    let sum = ref(0);
    let msg = ref("你好啊");
    let person = reactive({
      name: "张三",
      age: 18,
      job: {
        j1: {
          salary: 15,
        },
      },
    });

    //监视
    // watch(sum, (newVal, oldVal) => {
    //   console.log("sum变化了 :>> ", newVal, oldVal);
    // },{immediate:true});

    watchEffect(() => {
      // 智能的，用到谁就会监听到谁

      const x1 = sum.value;
      const x2 = person.job.j1.salary;

      console.log('watchEffect监听到了~');
    })
    

    return {
      sum,
      msg,
      person,
    };
  },
};
</script>
